(function($){
    $.fn.extend({
        /**************************************
         ******* 当调用dialog时，需要方式事件被多次执行 ==>使用unbind,bind方法
         ******* shown方法也要unbind ==> bind ==> modal("show"),防止options的值没有传入
         *******
         **************************************/
        showBisDataDialog : function (options) {
            //定义返回类型和返回json格式
            var _NORMAL        = "0000000";
            var action_flg     = options.action_flg;
            var data_seq_id    = options.data_seq_id;
            var data_cate      = options.data_cate;
            var data_cate_desc = options.data_cate_desc;

            var defaults = {
                callbackFn : null
            };
            var config = $.extend(defaults, options || {});
            var resultObj={
                result: false
            };

            /*** 将Div实例化为modal窗体 ***/
            $('#bis_data_6100_Dialog').modal({
                backdrop:true,
                keyboard:false,
                show:false
            });
            /***
             (1)show:false 则需要执行modal('show')方法
             (2)需要unbind('show')，避免 未获取options传过来的数据之前,就showDialog

             ***/
            function translateFnc(){
                var dia_dataIdLbl= $("#dia_dataIdLbl"),
                    dia_dataExtLbl= $("#dia_dataExtLbl"),
                    dia_dataItemLbl= $("#dia_dataItemLbl"),
                    dia_dataDescLbl= $("#dia_dataDescLbl"),
                    dia_ext1Lbl= $("#dia_ext1Lbl"),
                    dia_ext2Lbl= $("#dia_ext2Lbl"),
                    dia_ext3Lbl= $("#dia_ext3Lbl"),
                    dia_ext4Lbl= $("#dia_ext4Lbl"),
                    dia_ext5Lbl= $("#dia_ext5Lbl"),
                    dia_ext6Lbl= $("#dia_ext6Lbl"),
                    dia_ext7Lbl= $("#dia_ext7Lbl"),
                    dia_ext8Lbl= $("#dia_ext8Lbl"),
                    dia_ext9Lbl= $("#dia_ext9Lbl"),
                    dia_ext10Lbl= $("#dia_ext10Lbl"),
                    tbl_cnt,
                    iary,
                    inTrxObj,
                    outTrxObj;
                iary = {
                    data_cate : "CODE",
                    data_id   : $("#dia_dataCateSel").val()
                };
                inTrxObj = {
                    trx_id     : 'XPBASICDATA',
                    action_flg : "Q",
                    iary       : [iary],
                    tbl_cnt    : 1
                };
                outTrxObj = comTrxSubSendPostJson(inTrxObj);
                if( outTrxObj.rtn_code == _NORMAL ) {
                    tbl_cnt = outTrxObj.tbl_cnt;
                    for(var i=0;i<tbl_cnt;i++){
                        var oary = outTrxObj.oary[i];
                        switch(oary.dataExt){
                            case "DATA_ID":
                                dia_dataIdLbl.text(oary.dataDesc);
                                break;
                            case "DATA_EXT":
                                dia_dataExtLbl.text(oary.dataDesc);
                                break;
                            case "DATA_ITEM":
                                dia_dataItemLbl.text(oary.dataDesc);
                                break;
                            case "DATA_DESC":
                                dia_dataDescLbl.text(oary.dataDesc);
                                break;
                            case "EXT_1":
                                dia_ext1Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_2":
                                dia_ext2Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_3":
                                dia_ext3Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_4":
                                dia_ext4Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_5":
                                dia_ext5Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_6":
                                dia_ext6Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_7":
                                dia_ext7Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_8":
                                dia_ext8Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_9":
                                dia_ext9Lbl.text(oary.dataDesc);
                                break;
                            case "EXT_10":
                                dia_ext10Lbl.text(oary.dataDesc);
                                break;
                        }
                    }
                }
            }

            function dialogShowFnc(){
                if(action_flg=="A") {
                    $("#bis_data_Dialog_title").text("参数新增");
                    $("#bis_data_6100_Dialog input").val("");
                    $("#dia_dataCateSel").empty();
                    $("#dia_dataCateSel").append("<option value=" + data_cate + ">" + data_cate_desc + "</option>");
                }
                translateFnc();
            }
            function diaLogf5UpdateFnc() {
                var iary = {
                    dataSeqid: data_seq_id,
                    dataCate: $("#dia_dataCateSel").val(),
                    dataId: $("#dia_dataIdTxt").val(),
                    dataExt: $("#dia_dataExtTxt").val(),
                    dataItem: $("#dia_dataItemTxt").val(),
                    dataDesc: $("#dia_dataDescTxt").val(),
                    ext_1: $("#dia_ext1Txt").val(),
                    ext_2: $("#dia_ext2Txt").val(),
                    ext_3: $("#dia_ext3Txt").val(),
                    ext_4: $("#dia_ext4Txt").val(),
                    ext_5: $("#dia_ext5Txt").val(),
                    ext_6: $("#dia_ext6Txt").val(),
                    ext_7: $("#dia_ext7Txt").val(),
                    ext_8: $("#dia_ext8Txt").val(),
                    ext_9: $("#dia_ext9Txt").val(),
                    ext_10: $("#dia_ext10Txt").val(),
                    evtUsr: $("#userSpan").text(),
                    unqSeqId: $("#unq_seqTxt").val(),
                };
                var inTrxObj = {
                    trx_id: 'XPBASICDATA',
                    action_flg: action_flg,
                    iary: [iary],
                    tbl_cnt: 1
                };
                var outTrxObj = comTrxSubSendPostJson(inTrxObj);
                if (outTrxObj.rtn_code == _NORMAL) {
                    resultObj.result = true;
                    resultObj.outTrx = outTrxObj;
                    if (action_flg == "A") {
                        $('#bis_data_6100_Dialog').modal("hide");
                    }
                    getGridData();
                }
            }

            /*****
             当多次弹出对话框的同时也会多次绑定click事件。
             解决办法: 在show Dialog时将click unbind全部掉
             然后再绑定，这样就只剩下一个click事件了。
             **********/
            $('#bis_data_6100_Dialog').unbind('shown.bs.modal');
            $("#bisDataDialog_f5update_Btn").unbind('click');
            $("#dia_dataCateSel").unbind('change');
            $('#bis_data_6100_Dialog').modal("show");
            dialogShowFnc();
            $("#bisDataDialog_f5update_Btn").bind('click',diaLogf5UpdateFnc);
            /*****
             弹出提示,当获取焦点时
             需要包括: bootstrap-tooltip.js
             ******/
            $('[rel=tooltip]').tooltip({
                placement:"bottom",
                trigger:"focus",
                animation:true,
            });
            $("#dia_dataCateSel").select2({width: '100%'});
        }
    });
})(jQuery);




